package org.ilovecode.mvc
{
	import flash.display.MovieClip;
	import flash.display.Sprite;
	import flash.events.Event;
	
	public class View extends MovieClip implements IView
	{
		
		protected var model:IModel;
		protected var controller:IController;
		protected var _name:String;
		
		public function View(name:String = "")
		{
			super();
			
			if (name != "")
				this._name = name;
			
			model = Model.getInstance();
			controller = Controller.getInstance();
			
			(this.stage != null) ? init() :this.addEventListener(Event.ADDED_TO_STAGE, init);
		}
		
		private function init(event:Event = null):void
		{
			if (this.hasEventListener(Event.ADDED_TO_STAGE)) 
				this.removeEventListener(Event.ADDED_TO_STAGE, init);
			
			this.addEventListener(Event.REMOVED_FROM_STAGE, destroy);
			construct();
			initText();
			initUI();
			addListeners();
		}
		
		private function destroy(event:Event):void
		{
			this.removeEventListener(Event.REMOVED_FROM_STAGE, destroy);
			removeListeners();
		}
		
		protected function construct():void
		{
			// TODO Auto Generated method stub
			
		}
		
		protected function initUI():void
		{
			// TODO Auto Generated method stub
			
		}
		
		protected function initText():void
		{
			// TODO Auto Generated method stub
			
		}
		
		protected function addListeners():void
		{
			// TODO Auto Generated method stub
			
		}
		
		protected function removeListeners():void
		{
			// TODO Auto Generated method stub
			
		}
		
		protected function update(event:Event):void
		{
			
		}
	}
}